Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unenv

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unenv

`unenv` is a framework-agnostic system that allows converting JavaScript code to be platform agnostic and work in any environment including Browsers, Workers, Node.js, or JavaScript runtime.

  • 1.10.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
531K
decreased by-53.77%
Maintainers
1
Weekly downloads
 
Created

What is unenv?

The 'unenv' npm package is designed to provide a universal environment for JavaScript and TypeScript projects. It allows developers to create isomorphic code that can run seamlessly in both Node.js and browser environments by providing polyfills and shims for various APIs.

What are unenv's main functionalities?

Polyfills for Node.js APIs

This feature provides polyfills for Node.js APIs, allowing you to use Node.js-specific features in a browser environment. The code sample demonstrates how to use the Buffer API from Node.js in a universal environment.

const { Buffer } = require('unenv/runtime/polyfills/buffer');
const buffer = Buffer.from('Hello, world!');
console.log(buffer.toString('utf-8'));

Environment Detection

This feature allows you to detect the current environment (Node.js or browser) and execute code conditionally based on that. The code sample shows how to check if the code is running in Node.js or a browser.

const { isNode, isBrowser } = require('unenv');
if (isNode) {
  console.log('Running in Node.js');
} else if (isBrowser) {
  console.log('Running in the browser');
}

Universal Fetch API

This feature provides a universal Fetch API that works in both Node.js and browser environments. The code sample demonstrates how to make a fetch request and handle the response.

const fetch = require('unenv/runtime/polyfills/fetch');
fetch('https://api.example.com/data')
  .then(response => response.json())
  .then(data => console.log(data));

Other packages similar to unenv

FAQs

Package last updated on 16 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc